package com.edu.edu.week_project01.activity.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

/**
 * Created by Administrator on 10/12 0012.
 */
public class LbPageAdapter extends PagerAdapter{

    private List<ImageView> images;
    public LbPageAdapter(List<ImageView> image){
        this.images = image;
    }

    //决定了ViewPager内部子控件的数量.
    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    //用来初始化,产生一个条目(子视图),类似于getView()方法.
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        //将某个子view添加到容器中
        container.addView(images.get(position % images.size()));

        return images.get(position % images.size());
    }

    //判断这个view和这个object是否相等.
    @Override
    public boolean isViewFromObject(View view, Object object) {

        return view == object;
    }


    //移除(出)某个条目.
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        //从容器中移除某个条目
        container.removeView(images.get(position % images.size()));
    }
}
